'Submission
Option Strict Off
imports System
imports PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement
imports System.Collections

module Script
    sub Main()
		
        Dim questionnaireAnswers As new ArrayList()
        Dim qV As FormsManagement.QuestionnaireVersion
        Dim questionnaireAnswer As FormsManagement.QuestionnaireAnswer
        
        dim processType as string = currentProcess.Type
        select case processType
		
		'''''''''''''''''''''''''''''
		'Initial Review
		'''''''''''''''''''''''''''''
		'case PHSRAG.Insight21.Humans.Constants.ProtocolProcessType.InitialReview
	    case "PPTYPE_IR"
	       
			questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
			For Each questionnaireAnswer In questionnaireAnswers
				
				qV  = questionnaireAnswer.QuestionnaireVersion
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  ENROLLMENT NUMBERS
				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
				If (qV.Questionnaire.Name = "Study Population") Then
					Dim answers as new ArrayList()
					answers = questionnaireAnswer.GetAnswers("PHSEnroll") 
					If (answers.Count > 0) Then
						Dim i as integer = 0
						Try
							Dim phsEnrollAnswer as FormsManagement.Answer = answers(0)
							if IsNumeric ( phsEnrollAnswer.Value ) then
								i = FormatNumber(phsEnrollAnswer.Value)
							end if
						Catch
						End Try
						rexParams.SubjectCount = i
					End If
					answers = questionnaireAnswer.GetAnswers("AllEnroll")
					If (answers.Count > 0) Then
						Dim i as integer = 0
						Try
							Dim allEnrollAnswer as FormsManagement.Answer = answers(0)
							if IsNumeric ( allEnrollAnswer.Value ) then
								i = FormatNumber(allEnrollAnswer.Value)
							end if
						Catch
						End Try
						rexParams.GlobalEnrollment = i
					End If
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Medical Records
				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
				If (qV.Questionnaire.Name = "Health / Medical Records") Then
				
					' Override the type to Med Rec
					rexParams.ProtocolTypeOverride = PHSRAG.Insight21.Humans.Constants.RexProtocolType.DiscardedHumanMatAndMedRec
				
					rexParams.MedicalRecords = true
					Dim answers = questionnaireAnswer.GetAnswers("StudyPopulation")
					if answers.Count > 0 then
						Dim descrip as FormsManagement.Answer = answers(0)
						rexParams.StudyPopulationDescription = descrip.Value
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("RecordingIdent")
					if answers.Count > 0 then
						Dim descrip as FormsManagement.Answer = answers(0)
						if descrip.Value = "Y" then
							rexParams.MedRecIdentifiers = 1
						else	
							rexParams.MedRecIdentifiers = 0
						end if
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SendInfoOut")
					if answers.Count > 0 then
						Dim descrip as FormsManagement.Answer = answers(0)
						if descrip.Value = "Y" then
							rexParams.MedRecDisclose = 1
						else	
							rexParams.MedRecDisclose = 0
						end if
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("PeriodBeginningDate")
					if answers.Count > 0 then
						Dim dateAns as FormsManagement.Answer = answers(0)
						if IsDate(dateAns.Value) then
							rexParams.HumMatSurveyStart = dateAns.Value
						end if
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("PeriodEndDate")
					if answers.Count > 0 then
						Dim dateAns as FormsManagement.Answer = answers(0)
						if IsDate(dateAns.Value) then
							rexParams.HumMatSurveyEnd = dateAns.Value
						end if
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SourceHealthInformation")
					if answers.Count > 0 then
						Dim sourceAnswer As FormsManagement.Answer
						For Each sourceAnswer In answers
							if  sourceAnswer.Value = "bwh"  Then
								rexParams.MedicalRecordSources.Add ( "BWH" )
							else if sourceAnswer.Value = "faulkner" Then
								rexParams.MedicalRecordSources.Add ( "Faulkner" )
							else if sourceAnswer.Value = "mgh" Then
								rexParams.MedicalRecordSources.Add ( "MGH" )
							else if sourceAnswer.Value = "nsmc" Then
								rexParams.MedicalRecordSources.Add ( "NSMC" )
							else if sourceAnswer.Value = "pchi" Then
								rexParams.MedicalRecordSources.Add ( "PCHI" )
							else if sourceAnswer.Value = "srh" Then
								rexParams.MedicalRecordSources.Add ( "SRH" )	
							else if sourceAnswer.Value = "other" Then
								rexParams.MedicalRecordSources.Add ( "Other" )
							end if
						Next						
				
					end if
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Excess Human Material
				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
				If (qV.Questionnaire.Name = "Excess Human Material") Then
					rexParams.HumanMaterial = true
					Dim answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SourceBWH")	
					if answers.Count > 0 then
						Dim sourceAnswer As FormsManagement.Answer
						For Each sourceAnswer In answers
							if  sourceAnswer.Value = "Blood"  Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Blood Bank" )
							else if sourceAnswer.Value = "Labs" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Clinical Laboratories" )
							else if sourceAnswer.Value = "Crimsom" Then
								rexParams.HumanMaterialSources.Add ( "BWH Crimsom Repository" )
							else if sourceAnswer.Value = "LD" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Labor/Delivery" )
							else if sourceAnswer.Value = "OR" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Operating Room" )
							else if sourceAnswer.Value = "Pathology" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Pathology" )
							end if
						Next					
					end if
					
					' Faulkner
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialFaulkner")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "Faulkner" )
					end if
					
					' NWH - have Dan Add this to TblListValues.
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialNWH")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NWH" )
					end if
					
					' NSMC
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialNSMC")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NSMC" )
					end if
					
					' PCHI
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialPCHI")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NSMC" )
					end if
										
					' SRH
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialSRH")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "SRH" )
					end if
					
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SourceOtherSpecify")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "Other" )
						Dim descrip as FormsManagement.Answer = answers(0)
						rexParams.HumMatDescription = descrip.Value
					end if
					
					''' MGH
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SourceMGH")	
					if answers.Count > 0 then
						Dim sourceAnswer As FormsManagement.Answer
						For Each sourceAnswer In answers
							if  sourceAnswer.Value = "Blood"  Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Blood Bank" )
							else if sourceAnswer.Value = "Labs" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Clinical Laboratories" )
							else if sourceAnswer.Value = "LD" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Labor/Delivery" )
							else if sourceAnswer.Value = "OR" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Operating Room" )
							else if sourceAnswer.Value = "Pathology" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Pathology" )
							end if
						Next					
					end if
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("StudyPopulation")
					if answers.Count > 0 then
						Dim descrip as FormsManagement.Answer = answers(0)
						rexParams.HumMatDescription = descrip.Value
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("RecordingIdent")
					if answers.Count > 0 then
						Dim ident as FormsManagement.Answer = answers(0)
						if ident.Value = "Y"
							rexParams.MedRecIdentifiers = 1
						else 
							rexParams.MedRecIdentifiers = 0
						end if
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SendInfoOut")
					if answers.Count > 0 then
						Dim ident as FormsManagement.Answer = answers(0)
						if ident.Value = "Y"
							rexParams.MedRecDisclose = 1
						else 
							rexParams.MedRecDisclose = 0
						end if
					end if
					
					
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  PERFORMANCE SITES 
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				If (qV.Questionnaire.Name = "Performance Sites") Then
			
					Dim answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SiteBWH")	
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ( "BWH" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SiteMGH")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("MGH" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SiteFaulkner")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("Faulkner Hospital" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SiteNSMC")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("NSMC" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SitePCHI")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("PCHI" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SiteSRH")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("SRH" )
					end if
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("SiteNWH")
					if answers.Count > 0 then
						rexParams.PartnersSites.Add ("NWH" )
					end if
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Ionizing Radiation
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Ionizing Radiation") Then
					
					Dim procedureAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Procedure")	
					if procedureAnswers.Count > 0 then
						Dim procedureAnswer As FormsManagement.Answer
						For Each procedureAnswer In procedureAnswers
							if  procedureAnswer.Value = "Xray"  Then
								rexParams.Radiations.Add ( "X-ray Procedures" )
							else if procedureAnswer.Value = "Radio" Then
								rexParams.Radiations.Add ( "Radioactive Materials" )
							else if procedureAnswer.Value = "Fluoro" Then
								rexParams.Radiations.Add ( "Fluoroscopy" )
							end if
						Next					
					end if
				
				End If
				
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Non-Ionizing Radiation
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Non-Ionizing Radiation") Then
					
					Dim procedureAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Source")	
					if procedureAnswers.Count > 0 then
						Dim procedureAnswer As FormsManagement.Answer 
						For Each procedureAnswer In procedureAnswers
							if  procedureAnswer.Value = "MRI"  Then
								rexParams.Radiations.Add ( "MRI" )
							else if procedureAnswer.Value = "Ultra"  Then
								rexParams.Radiations.Add ( "Ultrasound" )
							else if procedureAnswer.Value = "Lasers"  Then
								rexParams.Radiations.Add ( "Laser\Ultraviolet Radiation" )
							end if
						Next
					end if
				
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  DRUGS
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Drugs / Biologics / Dietary Supplements") Then
					
					Dim newDrug as RexParams.RexDrug = new RexParams.RexDrug
					rexParams.Drugs.Add ( newDrug )
					newDrug.DrugName = questionnaireAnswer.Name
					newDrug.ExternalId = questionnaireAnswer.ExternalId
					
					Dim drugAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("StudyPhaseDesign")	
					if drugAnswers.Count > 0 then
						Dim studyPhaseAnswer as FormsManagement.Answer = drugAnswers(0)
						newDrug.StudyPhase = studyPhaseAnswer.Value
					else
						newDrug.StudyPhase = "I"
					end if
					
					drugAnswers = nothing
					drugAnswers = questionnaireAnswer.GetAnswers("INDNumber")
					if drugAnswers.Count > 0 then
						Dim indNumberAnswer as FormsManagement.Answer = drugAnswers(0)
						newDrug.IndNumber = indNumberAnswer.Value
					end if
				    
					drugAnswers = nothing
					drugAnswers = questionnaireAnswer.GetAnswers("INDSponsor")
					if drugAnswers.Count > 0 then
						Dim indSpons as FormsManagement.Answer = drugAnswers(0)
						newDrug.SponsorOfIND = indSpons.Value
					end if
				   
					drugAnswers = nothing
					drugAnswers = questionnaireAnswer.GetAnswers("FDAStatusDrug")
					if drugAnswers.Count > 0 then
						Dim fdaStatus as FormsManagement.Answer = drugAnswers(0)
						newDrug.FDAStatus = fdaStatus.Value
					end if
					
					drugAnswers = nothing
					drugAnswers = questionnaireAnswer.GetAnswers("DrugDispensed")
					if drugAnswers.Count > 0 then
						Dim dispensed as FormsManagement.Answer = drugAnswers(0)
						newDrug.Dispensing = dispensed.Value
						
						if  dispensed.Value = "Other" then
							Dim otherDescs as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("OtherDrugDispensed")	
							if otherDescs.Count > 0 then
								dim otherDispensDesc as FormsManagement.Answer = otherDescs(0)
								newDrug.DispensingOther = otherDispensDesc.value
							end if
						end if
					end if
				
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  DEVICES
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Medical Devices") Then
					
					Dim newDevice as RexParams.RexDevice = new RexParams.RexDevice
					rexParams.Devices.Add ( newDevice )
					newDevice.DeviceName = questionnaireAnswer.Name
					newDevice.ExternalId = questionnaireAnswer.ExternalId
					
					Dim deviceAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("InvestigationalDevice")
					if deviceAnswers.Count > 0 then
						Dim ideNumberAnswer as FormsManagement.Answer = deviceAnswers(0)
						newDevice.IdeNumber = ideNumberAnswer.Value
					end if
				    
					deviceAnswers = nothing
					deviceAnswers = questionnaireAnswer.GetAnswers("IdeHolder")
					if deviceAnswers.Count > 0 then
						Dim ideSpons as FormsManagement.Answer = deviceAnswers(0)
						newDevice.SponsorOfIDE = ideSpons.Value
					end if
				   
					deviceAnswers = nothing
					deviceAnswers = questionnaireAnswer.GetAnswers("FDAStatus2")
					if deviceAnswers.Count > 0 then
						Dim fdaStatus as FormsManagement.Answer = deviceAnswers(0)
						newDevice.FDAStatus = fdaStatus.Value
					end if
				    
					deviceAnswers = nothing
					deviceAnswers = questionnaireAnswer.GetAnswers("Risk")
					if deviceAnswers.Count > 0 then
						Dim nonSigRisk as FormsManagement.Answer = deviceAnswers(0)
						newDevice.NonSigRisk = nonSigRisk.Value
					end if
				    
				
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  SUBJECT POPULATION
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  ImpairedDecisionMaking
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Impaired Decision Making") Then
					rexParams.SubjectTypes.Add ("Type-Decisionally Impaired" )
				End If
					
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Pregnant Women or Human Fetuses
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Pregnant Women or Human Fetuses") Then
					rexParams.SubjectTypes.Add ("Type-Pregnant Women/Fetuses" )
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Children
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Children") Then
					Dim childrenAges as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Assent")	
					if childrenAges.Count > 0 then
						Dim assentAnswer As FormsManagement.Answer = childrenAges(0)
						if assentAnswer.Value = "Y" Then
							rexParams.SubjectTypes.Add ("Age-Children (2-12)" )		
						end if
					end if
				
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Study Population - has a few Subject types
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Study Population" ) Then
					Dim subjectCategories as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SubjCat")	
					if subjectCategories.Count > 0 then
						Dim subjAnswer As FormsManagement.Answer
					    
						For Each subjAnswer In subjectCategories
							if  subjAnswer.Value <> "None"  Then
								rexParams.SubjectTypes.Add ( subjAnswer.Value )
							End If 
						Next
					end if
							
				end if
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Research Data Repository
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Research Data Repository" ) Then
					
					Dim RDRSources as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SourceData")	
					if RDRSources.Count > 0 then
						Dim rdrSource As FormsManagement.Answer
						
						rexParams.MedicalRecords = true
						
						For Each rdrSource in RDRSources
							if rdrSource.Value = "BWH" Then
								rexParams.MedicalRecordSources.Add ("BWH")
							else if rdrSource.Value = "FH" Then
								rexParams.MedicalRecordSources.Add ("Faulkner")
							else if rdrSource.Value = "MGH" Then
								rexParams.MedicalRecordSources.Add ("MGH" )
							else if rdrSource.Value = "NWH" Then
								rexParams.MedicalRecordSources.Add ("NWH")
							else if rdrSource.Value = "NSMC" Then
								rexParams.MedicalRecordSources.Add ("NSMC")
							else if rdrSource.Value = "PCHI" Then
								rexParams.MedicalRecordSources.Add ("PCHI")
							else if rdrSource.Value = "SRH" Then
								rexParams.MedicalRecordSources.Add ("SRH")
							else if rdrSource.Value = "Other" Then
								rexParams.MedicalRecordSources.Add ("Other")
							end if								
						Next
						
					end if
					
					' Add the description.
					Dim RDROtherSources as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SourceOther")	
					if RDROtherSources.Count > 0 then
						Dim rdrSourceOther As FormsManagement.Answer = RDROtherSources(0)
						rexParams.MedSourceOther = rdrSourceOther.Value
					end if
										
					' Consent Obtained
					Dim consentObtaineds as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("ConsentObtained")	
					if consentObtaineds.Count > 0 then
						Dim consentObtained As FormsManagement.Answer  = consentObtaineds(0)
						if consentObtained.Value = "Y" then
							rexParams.ConsentWaived = true
							rexParams.AuthorizationWaived = true
						end if
					end if
					
					
					' SenttoCollaborators
					Dim collaborators as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Collaborators")	
					if collaborators.Count > 0 then
						Dim collaborator As FormsManagement.Answer  = collaborators(0)
						if collaborator.Value = "Y" then
							rexParams.MedRecDisclose = true
						end if
					end if
					
					
				end if
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Tissue or Sample Repository
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'Tissue or Sample Repository
				if (qV.Questionnaire.Name = "Tissue or Sample Repository" ) Then
				
					' change the ProtocolType to 
					rexParams.ProtocolTypeOverride = PHSRAG.Insight21.Humans.Constants.RexProtocolType.DiscardedHumanMatAndMedRec				
				
					'''' BWH Sources.
					Dim bwhSources as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("BWHSource")	
					if bwhSources.Count > 0 then
						Dim bwhSource As FormsManagement.Answer
					    
						For Each bwhSource In bwhSources
							rexParams.HumanMaterial = 1
							
							if  bwhSource.Value = "Blood"  Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Blood Bank" )
							else if bwhSource.Value = "Labs" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Clinical Laboratories" )
							else if bwhSource.Value = "Crimsom" Then
								rexParams.HumanMaterialSources.Add ( "BWH Crimsom Repository" )
							else if bwhSource.Value = "LD" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Labor/Delivery" )
							else if bwhSource.Value = "OR" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Operating Room" )
							else if bwhSource.Value = "Pathology" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Pathology" )									
							End If 
						Next
					End if
					
					''''''''''''''''''''''''''''''''''''''''''''''''''''''
					' Faulkner
					Dim answers as System.Collections.ArrayList 
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialFaulkner")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "Faulkner" )
					end if
					
					' NWH - have Dan Add this to TblListValues.
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialNWH")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NWH" )
					end if
					
					' NSMC
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialNSMC")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NSMC" )
					end if
					
					' PCHI
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialPCHI")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "NSMC" )
					end if
										
					' SRH
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("MaterialSRH")
					if answers.Count > 0 then
						rexParams.HumanMaterialSources.Add ( "SRH" )
					end if
					''''''''''''''''''''''''''''''''''''''''''''''''''''''
					
					'''' Other Sources.
					Dim otherSourceExs as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SourceOtherEx")	
					if otherSourceExs.Count > 0 then
						rexParams.HumanMaterial = 1
						
						Dim otherSourceEx As FormsManagement.Answer = otherSourceExs(0)
						
						rexParams.HumanMaterialSources.Add ("Other")
						rexParams.HumMatOtherDescription = otherSourceEx.Value							
					end if
					
					' Description
					Dim humanMatDescrips as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("DescribeMaterial")	
					if humanMatDescrips.Count > 0 then
						
						Dim humanMatDescrip As FormsManagement.Answer = humanMatDescrips(0)
						rexParams.HumMatDescription = humanMatDescrip.Value							
					end if
					
					''''' MGH Sources
					Dim mghSources as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("MGHSource")	
					if mghSources.Count > 0 then
						rexParams.HumanMaterial = 1
						Dim mghSource As FormsManagement.Answer
					    
						For Each mghSource In mghSources
							if  mghSource.Value = "Blood"  Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Blood Bank" )
							else if mghSource.Value = "Labs" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Clinical Laboratories" )
							else if mghSource.Value = "LD" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Labor/Delivery" )
							else if mghSource.Value = "OR" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Operating Room" )
							else if mghSource.Value = "Pathology" Then
								rexParams.HumanMaterialSources.Add ( "BWH/MGH Pathology" )									
							End If 
						Next
					End if
					
					Dim indicateMaterials as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("IndicateMaterial")	
					if indicateMaterials.Count > 0 then
						
						Dim indicateMaterial As FormsManagement.Answer 					    
						For Each indicateMaterial In indicateMaterials
							if  indicateMaterial.Value = "Minors"  Then
								rexParams.SubjectTypes.Add ( "Age-Adolescents (13-17)" )
							else if  indicateMaterial.Value = "Adults"  Then
								rexParams.SubjectTypes.Add ( "Age-Adults (18-64)" )
							else if  indicateMaterial.Value = "Older"  Then
								rexParams.SubjectTypes.Add ( "Age-Adults (65+)" )
							else if  indicateMaterial.Value = "Impaired"  Then
								rexParams.SubjectTypes.Add ( "Type-Decisionally Impaired" )
							end if
						Next
					
					end if
					
					' Cell Lines
					Dim specConsider As FormsManagement.Answer 
					Dim specConsiders as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("CellLines")	
					if specConsiders.Count > 0 then
						specConsider = specConsiders(0)
						if specConsider.Value = "Y" then
							rexParams.SpecialConsiderations.Add("Cell lines (permanent or immortal) to be developed")
						end if
					end if
					
					specConsider  = nothing
					specConsiders = nothing
					
					'Fetal Tissue
					specConsiders = questionnaireAnswer.GetAnswers("FetalTissue")
					if specConsiders.Count > 0 then
						specConsider = specConsiders(0)
						if specConsider.Value = "Y" then
							rexParams.SpecialConsiderations.Add("Fetal tissue will be used")
						end if
					end if	
					
					' Consent Obtained
					Dim consentObtaineds as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("ConsentObtained")	
					if consentObtaineds.Count > 0 then
						Dim consentObtained As FormsManagement.Answer  = consentObtaineds(0)
						if consentObtained.Value = "Y" then
							rexParams.ConsentWaived = true
							rexParams.AuthorizationWaived = true
						end if
					end if
					
					
					' SenttoCollaborators
					Dim collaborators as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SenttoCollaborators")	
					if collaborators.Count > 0 then
						Dim collaborator As FormsManagement.Answer  = collaborators(0)
						if collaborator.Value = "Y" then
							rexParams.MedRecDisclose = true
						end if
					end if
					
					
				end if
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Secondary Use of Samples
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				if (qV.Questionnaire.Name = "Secondary Use of Research Samples / Data" ) Then
				
					'Fetal Tissue
					Dim answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("StudyFetal")
					Dim answer as FormsManagement.Answer
					if answers.Count > 0 then
						answer = answers(0)
						if answer.Value = "Y" then
							rexParams.SpecialConsiderations.Add("Fetal tissue will be used")
						end if
					end if	
				
					answer = nothing
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Collaborators")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.Value = "Y" then
							rexParams.MedRecDisclose = 1
						else	
							rexParams.MedRecDisclose = 0
						end if
					end if
				
				end if
				
						
				'End If
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	
				'  END SUBJECT POPULATION
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Remunerations
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				If (questionnaireAnswer.Name = "Remuneration") Then
					
					Dim remunerationAnswers as 	System.Collections.ArrayList = questionnaireAnswer.GetAnswers("ParkCompType")	
					if remunerationAnswers.Count > 0 then
						Dim parkRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( parkRemun )
						parkRemun.Type = "Parking"
						Dim answersList = questionnaireAnswer.GetAnswers("ParkAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("ParkAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								Dim theAmount = FormatNumber(subAmount.Value)
								if theAmount = "" then
									theAmount = 0
								end if
								parkRemun.Amount = theAmount
							else parkRemun.Amount = 0
							end if
						end if
					end if
					
					remunerationAnswers = questionnaireAnswer.GetAnswers("GiftCertCompType")
					if remunerationAnswers.Count > 0 then
						Dim giftRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( giftRemun )
						giftRemun.Type = "Gift"
						Dim answersList = questionnaireAnswer.GetAnswers("GiftCertAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("GiftCertAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								giftRemun.Amount = FormatNumber(subAmount.Value)
							else giftRemun.Amount = 0
							end if
						end if
					end if
					
					remunerationAnswers = questionnaireAnswer.GetAnswers("CashCompType")
					if remunerationAnswers.Count > 0 then
						Dim cashRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( cashRemun )
						cashRemun.Type = "Cash"
						
						Dim answersList = questionnaireAnswer.GetAnswers("CashAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("CashAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								cashRemun.Amount = FormatNumber(subAmount.Value)
							else cashRemun.Amount = 0
							end if
						end if
					end if
					
					remunerationAnswers = questionnaireAnswer.GetAnswers("MealVoucherCompType")
					if remunerationAnswers.Count > 0 then
						Dim mealRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( mealRemun )
						mealRemun.Type = "Meals"
						Dim answersList = questionnaireAnswer.GetAnswers("VoucherAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("VoucherAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								mealRemun.Amount = FormatNumber(subAmount.Value)
							else mealRemun.Amount = 0
							end if
						end if
					end if
					
					remunerationAnswers = questionnaireAnswer.GetAnswers("TransCompType")
					if remunerationAnswers.Count > 0 then
						Dim transpRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( transpRemun )
						transpRemun.Type = "Transportation"
						Dim answersList = questionnaireAnswer.GetAnswers("TransAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("TransAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								transpRemun.Amount = FormatNumber(subAmount.Value)
							else transpRemun.Amount = 0
							end if
						end if
					end if
					
					remunerationAnswers = questionnaireAnswer.GetAnswers("OtherCompType")
					if remunerationAnswers.Count > 0 then
						Dim otherRemun as RexParams.RexRemuneration = new RexParams.RexRemuneration
						rexParams.Remunerations.Add ( otherRemun )
						otherRemun.Type = "Other"
						Dim answersList = questionnaireAnswer.GetAnswers("OtherAmt")
						if answersList.Count > 0 then
							Dim subAmount as FormsManagement.Answer = questionnaireAnswer.GetAnswers("OtherAmt")(0)	
							if IsNumeric ( subAmount.Value ) then
								otherRemun.Amount = FormatNumber(subAmount.Value)
							else otherRemun.Amount = 0
							end if
						end if
						' for Other, get teh description.
						answersList = nothing
						answersList = questionnaireAnswer.GetAnswers("OtherExplain")
						if answersList.Count > 0 then
							Dim descriptionAnswer as FormsManagement.Answer = answersList(0)
							otherRemun.OtherDescription = descriptionAnswer.Value
						end if
					end if
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Study Types
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				If (qV.Questionnaire.Name = "Study Details") Then
			
					Dim studyTypeAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("StudyType")	
					if studyTypeAnswers.Count > 0 then
						Dim studyTypeAnswer As FormsManagement.Answer
					       
							For Each studyTypeAnswer In studyTypeAnswers
								if  studyTypeAnswer.Value = "DataRep"  Then
									rexParams.StudyTypes.Add ( "Data Repository" )
								else if studyTypeAnswer.Value = "Diag"  Then
									rexParams.StudyTypes.Add ( "Diagnostic" )
								else if studyTypeAnswer.Value = "Epidem"  Then
									rexParams.StudyTypes.Add ( "Epidemiologic" )	
								else if studyTypeAnswer.Value = "Genetic"  Then
									rexParams.StudyTypes.Add ( studyTypeAnswer.Value )
								else if studyTypeAnswer.Value = "GeneTx"  Then
									rexParams.StudyTypes.Add ( "Gene Transfer" )
								else if studyTypeAnswer.Value = "HuESC"  Then
									rexParams.StudyTypes.Add ( "Human Embryonic Stem Cell" )
								else if studyTypeAnswer.Value = "Outcomes"  Then
									rexParams.StudyTypes.Add ( studyTypeAnswer.Value )
								else if studyTypeAnswer.Value = "PharmGenom"  Then
									rexParams.StudyTypes.Add ( "Pharmacogenomic" )					
								else if studyTypeAnswer.Value = "PK"  Then
									rexParams.StudyTypes.Add ( "Pharmacokinetic" )
								else if studyTypeAnswer.Value = "Phys"  Then
									rexParams.StudyTypes.Add ( "Physiologic" )
								else if studyTypeAnswer.Value = "Pilot"  Then
									rexParams.StudyTypes.Add ( studyTypeAnswer.Value )
								else if studyTypeAnswer.Value = "QI"  Then
									rexParams.StudyTypes.Add ( "Quality Improvement" )
								else if studyTypeAnswer.Value = "QOL"  Then
									rexParams.StudyTypes.Add ( "Quality of Life" )
								else if studyTypeAnswer.Value = "Safety"  Then
									rexParams.StudyTypes.Add ( studyTypeAnswer.Value )
								else if studyTypeAnswer.Value = "Survey"  Then
									rexParams.StudyTypes.Add ( studyTypeAnswer.Value )
								else if studyTypeAnswer.Value = "Therapy"  Then
									rexParams.StudyTypes.Add ( "Therapeutic" )
								else if studyTypeAnswer.Value = "TissueRep"  Then
									rexParams.StudyTypes.Add ( "Tissue Repository" )
								else if studyTypeAnswer.Value = "Trans"  Then
									rexParams.StudyTypes.Add ( "Translational" )
								else if studyTypeAnswer.Value = "Women"  Then
									rexParams.StudyTypes.Add ( "Women's Health" )	
								else if studyTypeAnswer.Value = "Other"  Then
									rexParams.StudyTypes.Add ( "Other" )										
								End If 
							Next
						
					end if
				End If
				
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				'  Recruitments...
				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
				If (qV.Questionnaire.Name = "Recruitment") Then
			
					Dim recruitAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("RecruitMaterials")	
					if recruitAnswers.Count > 0 then
						Dim recruitAnswer As FormsManagement.Answer
						For Each recruitAnswer In recruitAnswers
							if  recruitAnswer.Value = "News"  Then
								rexParams.Recruitment.Add ( "Ad- Newspaper" )
							else if recruitAnswer.Value = "Radio"  Then
								rexParams.Recruitment.Add ( "Ad- Radio" )
							else if recruitAnswer.Value = "TV"  Then
								rexParams.Recruitment.Add ( "Ad- Television" )
							else if recruitAnswer.Value = "Email"  Then
								rexParams.Recruitment.Add ( "Emails" )				
							else if recruitAnswer.Value = "Flyers"  Then
								rexParams.Recruitment.Add ( "Flyers/Posters" )
							else if recruitAnswer.Value = "Internet"  Then
								rexParams.Recruitment.Add ( "Internet Site Posting / Advertisement" )
							else if recruitAnswer.Value = "Letters"  Then
								rexParams.Recruitment.Add ( recruitAnswer.Value )
							else if recruitAnswer.Value = "Telephone"  Then
								rexParams.Recruitment.Add ( "Telephone Calls" )
							end if
						Next
					       
					end if
					
					recruitAnswers = nothing
					recruitAnswers = questionnaireAnswer.GetAnswers("SubjectSource")	
					if recruitAnswers.Count > 0 then
						Dim recruitAnswer As FormsManagement.Answer
						For Each recruitAnswer In recruitAnswers
							if  recruitAnswer.Value = "PubRec"  Then
								rexParams.Recruitment.Add ( "Census/Public Records" )
							else if recruitAnswer.Value = "CommMail"  Then
								rexParams.Recruitment.Add ( "Commercial Mailing Lists" )
							else if recruitAnswer.Value = "ED"  Then
								rexParams.Recruitment.Add ( "Emergency Department" )
							else if recruitAnswer.Value = "Inpt"  Then
								rexParams.Recruitment.Add ( "Inpatient Units" )
							else if recruitAnswer.Value = "MedRec"  Then
								rexParams.Recruitment.Add ( "Medical Records" )
							else if recruitAnswer.Value = "OPDClinic"  Then
								rexParams.Recruitment.Add ( "Outpatient Clinics" )
							else if recruitAnswer.Value = "Phys"  Then
								rexParams.Recruitment.Add ( "Primary Physician / Physician Specialist" )
							else if recruitAnswer.Value = "Reg"  Then
								rexParams.Recruitment.Add ( "Patient Registries" )
							else if recruitAnswer.Value = "RPDR"  Then
								rexParams.Recruitment.Add ( "Patient Information Databases" )
							else if recruitAnswer.Value = "RSVP"  Then
								rexParams.Recruitment.Add ( "RSVP for Health" )
							end if						
						Next
					end if
				end if
   			Next
   		
   		'''''''''''''''''''''''''''''
		'Adverse Event
		'''''''''''''''''''''''''''''	
   		case PHSRAG.Insight21.Humans.Constants.ProtocolProcessType.AdverseEvent
   		
   			questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
			For Each questionnaireAnswer In questionnaireAnswers
				
				qV  = questionnaireAnswer.QuestionnaireVersion
				If (qV.Questionnaire.Name = "Adverse Event Report Form") Then
					Dim answers as new ArrayList()
					answers = questionnaireAnswer.GetAnswers("SubjectID") 
					If (answers.Count > 0) Then
						Dim subjectId as FormsManagement.Answer = answers(0)
						rexParams.SubjectNumber = subjectId.Value
					End If
					answers = questionnaireAnswer.GetAnswers("EventExpected")
					If (answers.Count > 0) Then
						Dim i as integer = 0
							Dim expectedAnswer as FormsManagement.Answer = answers(0)
							' It seems backwards here, but that's because the question in Insight
							' is 'is the event UNexpected', so that's why we're doing the inverse here.
							if expectedAnswer.Value = "N" then
								rexParams.Expected = "Y"
							else
								rexParams.Expected = "N"
							end if
					End If 
					
					answers = questionnaireAnswer.GetAnswers("EventRelated")
					If (answers.Count > 0) Then
							Dim relatedAnswer as FormsManagement.Answer = answers(0)
							if relatedAnswer.Value = "Y" then
								rexParams.AERelated = "Likely"
							end if
					End If 
					
					answers = questionnaireAnswer.GetAnswers("EventSerious")
					If (answers.Count > 0) Then
							Dim seriousAnswer as FormsManagement.Answer = answers(0)
							if seriousAnswer.Value = "Y" then
								rexParams.AEGradeSeverity = "Serious"
							end if
					End If 
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("ReportType")
					if ( answers.Count > 0) Then
						Dim reportType as FormsManagement.Answer = answers(0)
						if reportType.Value = "Initial" then
							rexParams.AEReportType = reportType.Value
						else if reportType.Value = "FollowUp" then
							rexParams.AEReportType = "Followup"
						end if
					End if
					
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("EventDate")
					if ( answers.Count > 0) Then
						Dim AEDateAnswer as FormsManagement.Answer = answers(0)
						if IsDate(AEDateAnswer.Value) then
							rexParams.AEDateOccurred = AEDateAnswer.Value
						end if
					End if
				End If
   		
   			Next
   		'''''''''''''''''''''''''''''
		'Amendment
		'''''''''''''''''''''''''''''	
   		case PHSRAG.Insight21.Humans.Constants.ProtocolProcessType.Amendment
   		
   			questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
			For Each questionnaireAnswer In questionnaireAnswers
				
				qV  = questionnaireAnswer.QuestionnaireVersion

				' Sponsor Amendment number
				If (qV.Questionnaire.Name = "Amendment") Then
					Dim answers as new ArrayList()
					answers = questionnaireAnswer.GetAnswers("SponsorAmendNo") 
					If (answers.Count > 0) Then
						Dim sponsorAMENumberAnswer as FormsManagement.Answer = answers(0)
						rexParams.SponsorAMENumber = sponsorAMENumberAnswer.Value
					end if
					
					' Now go through each answer to figure out what the amendment is changing,
					' and add each to the ComponentsToChange string array list.
					' STUDY STAFF
					
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("AmendStaff")
					if ( answers.Count > 0) then
						Dim singleAnswer as FormsManagement.Answer = answers(0)
						if singleAnswer.Value = "Y" then
							Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
							rexParams.ComponentsToChange.Add ( newComponent )
							newComponent.Component = "Study Staff"
						end if					
					end if
					
					'Drugs
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Drugs")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Drug-Other"
					end if
					
					' Diaries
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Diaries")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Patient Diaries"
					end if
					
					'Recruitment
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Recruitment")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Recruitment Procedures"
					end if
					
					'Remuneration
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Remuneration")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Remuneration"
					end if
					
					'Sponsor
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Sponsor")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Sponsor"
					end if
					
					'Study Details
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("StudyDetails")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Study Type"
					end if
					
					'Title
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Title")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Protocol Title"
					end if
					
					'Version
					answers = nothing
					answers = questionnaireAnswer.GetAnswers("Version")
					if ( answers.Count > 0) then
						Dim newComponent as RexParams.ComponentToChange = new RexParams.ComponentToChange
						rexParams.ComponentsToChange.Add ( newComponent )
						newComponent.Component = "Version"
					end if
				
				end if
				
			Next
   		
   		'''''''''''''''''''''''''''''
		'Continuing Review
		'''''''''''''''''''''''''''''	
   		case PHSRAG.Insight21.Humans.Constants.ProtocolProcessType.ContinuingReview
   		
   			questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
			For Each questionnaireAnswer In questionnaireAnswers
				
				qV  = questionnaireAnswer.QuestionnaireVersion
				
				' EXCESS HUMAN MATERIAL!
				If (qV.Questionnaire.Name = "Continuing Review - Excess Human Material") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Samples") 
					Dim answer as FormsManagement.Answer 
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRSpecimensToDate = answer.value
						else 
							rexParams.CRSpecimensToDate = 0
						end if
					end if
					
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("MedicalRecords")
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRRecordsToDate = answer.value
						else 
							rexParams.CRRecordsToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Status")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "OngoingData" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B2	
						else if answer.value = "DataCompleted" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C4
						else if answer.value = "Completed" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
							' set the date closed field
							Dim dateclosedAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("DateClosed") 
							if dateclosedAnswers.Count > 0 then
								Dim dateClosedAnswer as FormsManagement.Answer = dateclosedAnswers(0)
								if IsDate(dateClosedAnswer.Value) then
									rexParams.CRDateClosed = dateClosedAnswer.value
								end if
							end if									
						end if
					end if
									
				end if  ' END EXCESS HUMAN MATERIAL!
				
				
				' Continuing Review - Health/Medical Information!
				If (qV.Questionnaire.Name = "Continuing Review - Health/Medical Information") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("NoRecords") 
					Dim answer as FormsManagement.Answer 
	
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRRecordsToDate = answer.value
						else 
							rexParams.CRRecordsToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Status")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "OngoingData" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B2	
						else if answer.value = "DataCompleted" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C4
						else if answer.value = "StudyCompleted" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
							' set the date closed field
							Dim dateclosedAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("DateClosed") 
							if dateclosedAnswers.Count > 0 then
								Dim dateClosedAnswer as FormsManagement.Answer = dateclosedAnswers(0)
								if IsDate(dateClosedAnswer.Value) then
									rexParams.CRDateClosed = dateClosedAnswer.value
								end if
							end if	
						end if
					end if
					
				end if ' END Health Medical Information.
				
				
				' Continuing Review - Research Data Repository!
				If (qV.Questionnaire.Name = "Continuing Review - Research Data Repository") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Medicalrecords") 
					Dim answer as FormsManagement.Answer 
	
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRRecordsToDate = answer.value
						else 
							rexParams.CRRecordsToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Status")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "Ongoing" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B2	
						else if answer.value = "AnalysisOnly" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C4
						else if answer.value = "ProjectEnded" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
							' set the date closed field
							Dim dateclosedAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Date") 
							if dateclosedAnswers.Count > 0 then
								Dim dateClosedAnswer as FormsManagement.Answer = dateclosedAnswers(0)
								if IsDate(dateClosedAnswer.Value) then
									rexParams.CRDateClosed = dateClosedAnswer.value
								end if
							end if	
						end if
					end if
	
				end if ' END Continuing Review - Research Data Repository
				
				
				' Continuing Review - Secondary Use of Samples/Data
				If (qV.Questionnaire.Name = "Continuing Review - Secondary Use of Samples/Data") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("SubjectsDataToDate") 
					Dim answer as FormsManagement.Answer 
	
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRRecordsToDate = answer.value
							rexParams.CRSpecimensToDate = answer.value
						else 
							rexParams.CRRecordsToDate = 0
							rexParams.CRSpecimensToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Useofsamples")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "Ongoing" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B2	
						else if answer.value = "Continues" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C4
						else if answer.value = "Closed" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
							' set the date closed field
							Dim dateclosedAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("DateClosed") 
							if dateclosedAnswers.Count > 0 then
								Dim dateClosedAnswer as FormsManagement.Answer = dateclosedAnswers(0)
								if IsDate(dateClosedAnswer.Value) then
									rexParams.CRDateClosed = dateClosedAnswer.value
								end if
							end if	
						end if
					end if
					
				end if ' END ' Continuing Review - Secondary Use of Samples/Data
				
				
				' Continuing Review - Tissue or Sample Repository
				If (qV.Questionnaire.Name = "Continuing Review - Tissue or Sample Repository") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Samples") 
					Dim answer as FormsManagement.Answer 
					
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRSpecimensToDate = answer.value
						else 
							rexParams.CRSpecimensToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Useofsamples")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "Ongoing" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B2	
						else if answer.value = "Continues" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C4
						else if answer.value = "Closed" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
						end if
					end if
					
								
				end if ' END Continuing Review - Tissue or Sample Repository
				
				
				' Continuing Review - Intervention / Interaction
				If (qV.Questionnaire.Name = "Continuing Review - Intervention / Interaction") Then
					
					Dim Answers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Samples") 
					Dim answer as FormsManagement.Answer 
					
					if answers.Count > 0 then
						answer = answers(0)
						if IsNumeric( answer.value ) then
							rexParams.CRSpecimensToDate = answer.value
						else 
							rexParams.CRSpecimensToDate = 0
						end if
					end if
					
					'Status
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("Status")
					if answers.Count > 0 then
						answer = answers(0)
						if answer.value = "OpenEnroll" then
							Dim noEnrollAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("ActiveNoEnrollment")
							if noEnrollAnswers.Count > 0 then
								Dim noEnrollAnswer as FormsManagement.Answer = noEnrollAnswers(0)
								if noEnrollAnswer.Value = "NoEnrollment" then
									rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.A2	
								end if
							else
								rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.B1	
							end if
						else if answer.value = "ClosedEnroll" then
							Dim closedEnrollAnswers as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("ClosedEnrollCat")
							if closedEnrollAnswers.Count > 0 then
								Dim closedEnrollAnswer as FormsManagement.Answer = closedEnrollAnswers(0)
								if closedEnrollAnswer.Value = "Treatment" then
									rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C1	
								else if closedEnrollAnswer.Value = "LongTerm" then
									rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C2	
								else if closedEnrollAnswer.Value = "DataAnal" then
									rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.C3	
								end if
							end if
						else if answer.value = "Completed" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.D
						else if answer.value = "Closed" then
							rexParams.CRProjectStatus = PHSRAG.Insight21.Humans.Constants.RexCRStatus.E1
						end if
					end if
					
					' THERE Are three types of date closeds here, but they are mutually exclusive
					' set the date closed field
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("ActiveDateClosed")
					if answers.Count > 0 then
						answer = answers(0)
						if IsDate(answer.Value) then
							rexParams.CRDateClosed = answer.value
						end if						
					end if
					
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("InactiveDateCompleted")
					if answers.Count > 0 then
						answer = answers(0)
						if IsDate(answer.Value) then
							rexParams.CRDateClosed = answer.value
						end if						
					end if
					
					answers = nothing
					answer = nothing
					answers = questionnaireAnswer.GetAnswers("InactiveDateClosed")
					if answers.Count > 0 then
						answer = answers(0)
						if IsDate(answer.Value) then
							rexParams.CRDateClosed = answer.value
						end if						
					end if
								
				end if ' END Continuing Review - Intervention / Interaction
				
			Next
   		
   		'''''''''''''''''''''''''''''
		'Other Event
		'''''''''''''''''''''''''''''	
   		case PHSRAG.Insight21.Humans.Constants.ProtocolProcessType.OtherEvent
   		
   			questionnaireAnswers= currentProtVersion.QuestionnaireAnswers
			For Each questionnaireAnswer In questionnaireAnswers
				
				qV  = questionnaireAnswer.QuestionnaireVersion
				Dim OEDescriptions as System.Collections.ArrayList
				Dim OEDescription  as FormsManagement.Answer
				Dim answers as new ArrayList()
				
				answers = questionnaireAnswer.GetAnswers("Type") 
				if answers.Count > 0 then
					Dim typeAnswer as FormsManagement.Answer = answers(0)
					if typeAnswer.Value = "Alert" then
						rexParams.OEEventType = "Alert Page"
						' Get teh description
						OEDescriptions = questionnaireAnswer.GetAnswers("AlertEx")	
						if OEDescriptions.Count > 0 then
							OEDescription = OEDescriptions(0)
							rexParams.OEDescription = OEDescription.Value
						end if
					
					else if typeAnswer.Value = "DSMB" then
						rexParams.OEEventType = "Data and Safety Monitoring Report"
						
						OEDescriptions = questionnaireAnswer.GetAnswers("Summary")	
						if OEDescriptions.Count > 0 then
							OEDescription = OEDescriptions(0)
							rexParams.OEDescription = OEDescription.Value
						end if
						
					else if typeAnswer.Value = "Exception" then
						rexParams.OEEventType = "Protocol Exception"
						OEDescriptions = questionnaireAnswer.GetAnswers("DescribeExcep")	
						if OEDescriptions.Count > 0 then
							OEDescription = OEDescriptions(0)
							rexParams.OEDescription = OEDescription.Value
						end if
						
					else if typeAnswer.Value = "Violation" then
						' Go get the type of violation- Major or Minor.
						Dim violationTypes as System.Collections.ArrayList = questionnaireAnswer.GetAnswers("Severity")	
						
						if violationTypes.Count > 0 then
							Dim violationType 	as FormsManagement.Answer = violationTypes(0)
							if violationType.Value = "Minor" then
								rexParams.OEEventType = "Violation, Minor"
								
								OEDescriptions = questionnaireAnswer.GetAnswers("DescribeVioMinor")	
								if OEDescriptions.Count > 0 then
									OEDescription = OEDescriptions(0)
									rexParams.OEDescription = OEDescription.Value
								end if
								
							else if violationType.Value = "Major" then
								rexParams.OEEventType = "Violation, Major"
								
								OEDescriptions = questionnaireAnswer.GetAnswers("DecribeVio")	
								if OEDescriptions.Count > 0 then
									OEDescription = OEDescriptions(0)
									rexParams.OEDescription = OEDescription.Value
								end if
							end if
						end if
						
					else if typeAnswer.Value = "Unantic" then
						rexParams.OEEventType = "Unanticipated Problem"
						OEDescriptions = questionnaireAnswer.GetAnswers("DescribeUnantic")	
						if OEDescriptions.Count > 0 then
							OEDescription = OEDescriptions(0)
							rexParams.OEDescription = OEDescription.Value
						end if
						
					else if typeAnswer.Value = "Other" then
						rexParams.OEEventType = "Other"
						OEDescriptions = questionnaireAnswer.GetAnswers("OtherExplain")	
						if OEDescriptions.Count > 0 then
							OEDescription = OEDescriptions(0)
							rexParams.OEDescription = OEDescription.Value
						end if
						
					end if
					
				end if
			
			Next
   			
   		end select 
		
    end sub	
end module